<template>
  <div class="container">
    <!--搜索-->
    <div v-show="front" class="handle-box">
      <el-input
        class="handle-input mr10"
        type="textarea"
        :rows="8"
        placeholder="输入原文"
        v-model="select_word"
        @keyup.enter.native="search">
      </el-input>
      <el-button
        style="margin-top: 20px;width: 100px"
        type="primary"
        icon="search"
        @click="search"
        v-loading.fullscreen.lock="fullscreenLoading">AI识别
      </el-button>
    </div>
    <div v-show="later">
      <p style="font-weight: bold;font-size: 15px;color: #7b7b7b;" v-html="this.original"></p>
      <el-button
        style="margin-top: 20px;width: 100px"
        type="primary"
        icon="search"
        @click="back">返回
      </el-button>
    </div>
    <!--数据显示-->
    <div>
      <h4>基本信息</h4>
      <div class="data">
        <p>
          <el-row :gutter="20">
            <el-col :span="12">
              <span>名字：</span><span>{{data.person}}</span>
            </el-col>
            <el-col :span="12">
              <span>职称：</span><span>{{data.zhiji}}</span>
            </el-col>
          </el-row>
        </p>
        <p>
          <el-row :gutter="20">
            <el-col :span="12">
              <span>科室：</span><span>{{data.dept}}</span>
            </el-col>
            <el-col :span="12">
              <span>医院：</span><span>{{data.hco}}</span>
            </el-col>
          </el-row>
        </p>
      </div>
      <h4>学习经历</h4>
      <el-table
        :data="data.school"
        border
        style="width: 100%">
        <el-table-column
          prop="time"
          label="时间">
        </el-table-column>
        <el-table-column
          prop="schoolName"
          label="学校">
        </el-table-column>
        <el-table-column
          prop="major"
          label="专业">
        </el-table-column>
        <el-table-column
          prop="record"
          label="学历">
        </el-table-column>
      </el-table>
      <h4>协会任职</h4>
      <el-table
        :data="data.ass"
        border
        style="width: 100%">
        <el-table-column
          prop="time"
          label="时间">
        </el-table-column>
        <el-table-column
          prop="assName"
          label="协会">
        </el-table-column>
        <el-table-column
          prop="title"
          label="任职">
        </el-table-column>
      </el-table>
    </div>
    <!--没有搜索到数据-->
    <el-dialog
      :visible.sync="centerDialogVisible"
      width="30%"
      center>
      <div style="text-align: center">
        <span
          style='display: inline-block;background: url("../../../static/img/weep.png") no-repeat;background-size:100%;width: 50px;height: 50px;vertical-align: middle;'></span>
        <span style="display:inline-block;font-size: 20px;font-weight: bold">没有搜索到数据!</span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        /*无数据*/
        centerDialogVisible: false,
        /*搜索*/
        select_word: '',
        original: '',
        front: true,
        later: false,
        /*数据*/
        data: {},
        /*加载*/
        fullscreenLoading: false,
        /*高亮颜色*/
        red: 'color:#FF3300;',
        olivine: 'color:#FF6600;',
        orange: 'color:#FE9901;',
      }
    },
    created() {

    },
    methods: {
      /*搜索*/
      search() {
        if (this.excludeSpecial(this.select_word).length > 0) {
          let Obj = {value: this.select_word};
          this.fullscreenLoading = true;
          this.POST(this.$com.GXUrl, '/nermdm/ner_info', Obj)
        } else {
          this.$message.warning('不能为空！');
        }
      },
      /*返回*/
      back() {
        this.original = '';
        this.later = false;
        this.front = true;
      },
      /*POST请求*/
      POST(Url, Port, data) {
        this.$axios({
          method: 'POST',
          headers: {'Content-Type': 'application/json;charset=UTF-8'},
          url: Url + Port,
          data: JSON.stringify(data),
        }).then((res) => {
          this.fullscreenLoading = false;
          if (res.data.result != '') {
            this.later = true;
            this.front = false;
            this.original = this.select_word;
            this.highlight(res.data.result.person, this.red);
            this.highlight(res.data.result.hco, this.red);
            this.highlight(res.data.result.zhiji, this.red);
            this.highlight(res.data.result.dept, this.red);
            for (let a of res.data.result.ass) {
              this.highlight(a.assName, this.olivine);
              this.highlight(a.time, this.olivine);
              this.highlight(a.title, this.olivine);
            }
            for (let b of res.data.result.school) {
              this.highlight(b.record, this.orange);
              this.highlight(b.major, this.orange);
              this.highlight(b.schoolName, this.orange);
              this.highlight(b.time, this.orange);
            }
            this.data = res.data.result;
          } else {
            this.data = {};
            this.centerDialogVisible = true;
            setTimeout(() => {
              this.centerDialogVisible = false;
            }, 1500);
          }
        })
      },
      /*去除非法字符*/
      excludeSpecial(s) {
        s = s.replace(/[^\u4e00-\u9fa5a-zA-Z0-9\w]/g, '');
        return s;
      },
      /*高亮*/
      highlight(parameter, colour) {
        if (parameter) {
          console.log(parameter)
          if (parameter.length >= 4 && this.original.indexOf(parameter) != -1) {
            let values = this.original.split(parameter);
            this.original = values.join('<font  style=' + colour + '>' + parameter + '</font >');
          }
          if (parameter.length < 4 && this.original.indexOf(parameter) != -1) {
            let values = this.original.split(parameter);
            this.original = values.join('<font  style=' + colour + '>' + parameter + '</font >');
          }
        }
      },
    },
  }
</script>

<style scoped>
  .container {
    padding: 30px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 5px;
  }

  /*搜索框*/
  .handle-input {
    /*    width: 300px;*/
    display: inline-block;
  }

  /**/
  .data {
    font-size: 13px;
  }
</style>
